package com.control;

import com.pojo.User;
import com.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(allowCredentials = "true")
public class UserControl {

    private final UserServiceImpl userService;

    @Autowired
    public UserControl(UserServiceImpl userService){
        this.userService = userService;
    }

    @RequestMapping("/get_all_user")
    public List<User> getAllUser(){
        return userService.findUserAll();
    }

    @RequestMapping("/log_in")
    public String logIn(String username, String password){
        return userService.logIn(username, password);
    }

    @RequestMapping("/log_on")
    public String logOn(String mail, String password, String name, String school, String role){
        return userService.logOn(mail, password, name, school, role);
    }

    @RequestMapping("/change_role")
    public String changeRole(String role, String id){
        return userService.changeRole(role, id);
    }

    @RequestMapping("/change_password")
    public String changePassword(String id, String password){
        return userService.changePassword(id, password);
    }

    @RequestMapping("/change_mail")
    public String changeMail(String id, String mail){
        return userService.changeMail(id, mail);
    }

    @RequestMapping("/change_tel")
    public String changeTel(String id, String tel){
        return userService.changeTel(id, tel);
    }

    @RequestMapping("/get_course_list_by_student_id")
    public List<String> getCourseListByStudentId(String id){
        return userService.getCourseListByStudentId(id);
    }

    @RequestMapping("/get_user_by_mail_or_tel")
    public List<User> getUserByMailOrTel(String value){
        return userService.getUserByMailOrTel(value);
    }
}
